package com.dxt.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.dxt.common.AppConstant;
import com.dxt.common.LogHelper;
import com.dxt.common.MyBusiException;
import com.dxt.message.AppRequestMessage;
import com.dxt.message.ReponseMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;

@Service("HYModifyThresholdValueService")
public class HYModifyThresholdValueService extends IBaseBusiService {
    private static final Logger logger = LoggerFactory.getLogger(Thread.currentThread().getStackTrace()[1].getClassName());

    @Autowired
    CacheManager cacheManager;

    @Override
    public ReponseMessage execute(String reqInfo, String url) {
        logger.debug(LogHelper._FUNC_START_());
        ReponseMessage message = new ReponseMessage();
        AppRequestMessage msg = getMsg();
        JSONObject jsonObject = JSON.parseObject(reqInfo);
        try {
            /**
             * 校验必填业务参数是否为空
             */
            checkParams(jsonObject,AppConstant.REQUEST_REPONSE_PARAM.PARAM_IN_DEVICEID/*,
                    AppConstant.REQUEST_REPONSE_PARAM.PARAM_IN_SET,
                    AppConstant.REQUEST_REPONSE_PARAM.PARAM_IN_HH,
                    AppConstant.REQUEST_REPONSE_PARAM.PARAM_IN_H,
                    AppConstant.REQUEST_REPONSE_PARAM.PARAM_IN_I,
                    AppConstant.REQUEST_REPONSE_PARAM.PARAM_IN_II*/);

        } catch (MyBusiException e) {
            message.setMsg(AppConstant.REPONSE_CODE.BUSI_ERROR, AppConstant.REPONSE_MSG.SYS_PARAM_ERROR_MSG,
                    e.getMessage());
            return message;
        }
        String deviceId = jsonObject.getString(AppConstant.REQUEST_REPONSE_PARAM.PARAM_IN_DEVICEID);
        String topic = deviceId+"/"+deviceId+"/set";
        //Map<String,Object> map = new HashMap<>();
        String values = jsonObject.getString("values");
        logger.info("合远阈值下发------------------------------{}",values);


        /*map.put("set",jsonObject.getString(AppConstant.REQUEST_REPONSE_PARAM.PARAM_IN_SET));
        map.put(AppConstant.REQUEST_REPONSE_PARAM.PARAM_IN_HH,
                jsonObject.getString(AppConstant.REQUEST_REPONSE_PARAM.PARAM_IN_HH));
        map.put(AppConstant.REQUEST_REPONSE_PARAM.PARAM_IN_H,
                jsonObject.getString(AppConstant.REQUEST_REPONSE_PARAM.PARAM_IN_H));
        map.put(AppConstant.REQUEST_REPONSE_PARAM.PARAM_IN_II,
                jsonObject.getString(AppConstant.REQUEST_REPONSE_PARAM.PARAM_IN_II));
        map.put(AppConstant.REQUEST_REPONSE_PARAM.PARAM_IN_I,
                jsonObject.getString(AppConstant.REQUEST_REPONSE_PARAM.PARAM_IN_I));*/
        //JSONObject json = new JSONObject(map);
        message.getReponseMessage(values,topic,deviceId,cacheManager,message);
        return message;
    }

    public static void main(String[] args) {
        String json = "{\"aaa\":\"bbb\"}";

        System.out.println(JSONObject.parse(json).toString());
    }

}
